package com.yaj.mesif.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yaj.mesif.dto.P2TCosnoDto;
import com.yaj.mesif.entity.P2TCosno;
import com.yaj.mesif.mapper.P2TCosnoMapper;
import com.yaj.mesif.service.P2TCosnoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wei
 * @since 2021-09-05
 */
@Service
public class P2TCosnoServiceImpl extends ServiceImpl<P2TCosnoMapper, P2TCosno> implements P2TCosnoService {
    @Resource
    private P2TCosnoMapper p2TCosnoMapper;

    @Override
    public boolean RegP2Cosno(P2TCosnoDto p2TCosnoDto) {
        long result = 0;
        P2TCosno p2TCosno = new P2TCosno();
        BeanUtil.copyProperties(p2TCosnoDto,p2TCosno);

        //取-前的订单号
        String orderNo = p2TCosno.getOrderNo().split("-")[0];
        p2TCosno.setOrderNo(orderNo);

        //查询该订单号是否登陆过，对应U8拆分多个订单，但Prime表中只需要登陆一次
        int count = p2TCosnoMapper.selectCount(new QueryWrapper<P2TCosno>().lambda().eq(P2TCosno::getOrderNo,orderNo));
        if(count==0){
            result  = p2TCosnoMapper.insertP2Cosno(p2TCosno);

            if (result == 1) {
                return true;
            }
        }else{
            return true;
        }

        return false;
    }
}
